'''
Author: your name
Date: 2021-11-05 10:24:26
LastEditTime: 2021-11-13 10:17:02
LastEditors: Please set LastEditors
Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
FilePath: /tinyms/tinyms-api/apps/cms/article/service.py
'''
import json
from app import db
from .model import Article

class ArticleService():
    '''
    查询所有文章
    '''
    def list():
        Articles = Article.query.filter().all()
        return Articles
    '''
    保存文章
    '''
    def save(article):
        db.session.add(article)
        db.session.commit()
    '''
    更新文章
    '''
    def update(article):
        tmp_article = Article.query.get(article.article_pk)
        tmp_article.article_content = article.article_content
        tmp_article.article_state = article.article_state
        db.session.commit()
    '''
    通过主键删除
    '''
    def delete(article_pk):
        article = Article.query.get(article_pk)
        db.session.delete(article)
        db.session.commit()

    '''
    分页查询
    '''
    def pages(page,limit):
        pages = Article.query.paginate(int(page), int(limit), False) #flask_sqlalchemy提供分页方法.paginate
        return pages
